package com.lz.gmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lz.gmall.common.result.Result;
import com.lz.gmall.common.result.ResultCodeEnum;
import com.lz.gmall.product.entity.BaseCategory2;
import com.lz.gmall.product.service.BaseCategory2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@Api(tags = "二级产品")
public class BaseCategory2Controller {

    @Autowired
    private BaseCategory2Service baseCategory2Service;

    /**
     * 根据一级产品id获取对应的二级产品
     * @return 二级产品集合
     */
    @GetMapping("/getCategory2/{category1Id}")
    @ApiOperation("获取产品的二级分类")
    public Result<List<BaseCategory2>> findAll(@PathVariable("category1Id") Long cate1Id){
        List<BaseCategory2> list = baseCategory2Service.findAllByCate1Id(cate1Id);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
}
